<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// 应用启动时的初始化逻辑
			this.initApp()
		},
		onShow: function() {
			console.log('App Show')
			// 应用显示时的逻辑
		},
		onHide: function() {
			console.log('App Hide')
			// 应用隐藏时的逻辑
		},
		methods: {
			initApp() {
				// 检查更新
				this.checkUpdate()
				
				// 获取系统信息
				this.getSystemInfo()
			},
			
			// 检查应用更新
			checkUpdate() {
				// #ifdef MP-WEIXIN
				if (uni.canIUse('getUpdateManager')) {
					const updateManager = uni.getUpdateManager()
					updateManager.onCheckForUpdate((res) => {
						if (res.hasUpdate) {
							updateManager.onUpdateReady(() => {
								uni.showModal({
									title: '更新提示',
									content: '新版本已经准备好，是否重启应用？',
									success: (res) => {
										if (res.confirm) {
											updateManager.applyUpdate()
										}
									}
								})
							})
							updateManager.onUpdateFailed(() => {
								uni.showModal({
									title: '更新失败',
									content: '新版本下载失败，请检查网络后重试',
									showCancel: false
								})
							})
						}
					})
				}
				// #endif
			},
			
			// 获取系统信息
			getSystemInfo() {
				// #ifdef MP-WEIXIN
				// 微信小程序使用新的API
				Promise.all([
					uni.getWindowInfo(),
					uni.getDeviceInfo(),
					uni.getAppBaseInfo(),
					uni.getSystemSetting()
				]).then(([windowInfo, deviceInfo, appBaseInfo, systemSetting]) => {
					// 合并系统信息
					const systemInfo = {
						...windowInfo,
						...deviceInfo,
						...appBaseInfo,
						...systemSetting
					}
					
					// 存储系统信息到全局
					this.globalData.systemInfo = systemInfo
					
					// 设置状态栏高度
					this.globalData.statusBarHeight = windowInfo.statusBarHeight
					
					// 设置导航栏高度
					this.globalData.navBarHeight = windowInfo.statusBarHeight + 44
				}).catch((error) => {
					console.error('获取系统信息失败:', error)
					// 降级处理：使用旧的API
					this.getSystemInfoFallback()
				})
				// #endif
				
				// #ifndef MP-WEIXIN
				// 其他平台使用通用API
				uni.getSystemInfo({
					success: (res) => {
						// 存储系统信息到全局
						this.globalData.systemInfo = res
						
						// 设置状态栏高度
						this.globalData.statusBarHeight = res.statusBarHeight
						
						// 设置导航栏高度
						this.globalData.navBarHeight = res.statusBarHeight + 44
					}
				})
				// #endif
			},
			
			// 降级处理：使用旧的API
			getSystemInfoFallback() {
				uni.getSystemInfo({
					success: (res) => {
						// 存储系统信息到全局
						this.globalData.systemInfo = res
						
						// 设置状态栏高度
						this.globalData.statusBarHeight = res.statusBarHeight
						
						// 设置导航栏高度
						this.globalData.navBarHeight = res.statusBarHeight + 44
					}
				})
			}
		},
		
		// 全局数据
		globalData: {
			systemInfo: {},
			statusBarHeight: 0,
			navBarHeight: 0
		}
	}
</script>

<style>
/* 全局样式重置 */
view, text, button, input, textarea, image, scroll-view, swiper, swiper-item {
  box-sizing: border-box;
}

page {
  background-color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #262626;
}

/* 布局工具类 */
.flex { display: flex; }
.flex-center { 
  display: flex; 
  align-items: center; 
  justify-content: center; 
}
.flex-between { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
}
.flex-column { 
  display: flex; 
  flex-direction: column; 
}
.flex-1 { flex: 1; }

/* 文本对齐 */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

/* 间距类 */
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }

.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 16px; }
.mb-lg { margin-bottom: 24px; }

.ml-sm { margin-left: 8px; }
.ml-md { margin-left: 16px; }
.ml-lg { margin-left: 24px; }

.mr-sm { margin-right: 8px; }
.mr-md { margin-right: 16px; }
.mr-lg { margin-right: 24px; }

.pt-sm { padding-top: 8px; }
.pt-md { padding-top: 16px; }
.pt-lg { padding-top: 24px; }

.pb-sm { padding-bottom: 8px; }
.pb-md { padding-bottom: 16px; }
.pb-lg { padding-bottom: 24px; }

.pl-sm { padding-left: 8px; }
.pl-md { padding-left: 16px; }
.pl-lg { padding-left: 24px; }

.pr-sm { padding-right: 8px; }
.pr-md { padding-right: 16px; }
.pr-lg { padding-right: 24px; }

/* 字体大小类 */
.text-sm { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }

/* 字体颜色类 */
.text-primary { color: #262626; }
.text-secondary { color: #595959; }
.text-success { color: #52C41A; }
.text-warning { color: #FAAD14; }
.text-error { color: #FF4D4F; }
.text-info { color: #1890FF; }

/* 背景颜色类 */
.bg-white { background-color: #fff; }
.bg-light { background-color: #FAFAFA; }
.bg-primary { background-color: #007AFF; }

/* 边框类 */
.border { border: 1px solid #D9D9D9; }
.border-light { border: 1px solid #F0F0F0; }

/* 圆角类 */
.rounded { border-radius: 4px; }
.rounded-lg { border-radius: 8px; }
.rounded-circle { border-radius: 50%; }

/* 阴影类 */
.shadow { box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.shadow-light { box-shadow: 0 1px 4px rgba(0,0,0,0.1); }

/* 按钮样式 */
.btn {
  background-color: #007AFF;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}
.btn-secondary {
  background-color: #fff;
  color: #007AFF;
  border: 1px solid #007AFF;
}
.btn-block {
  width: 100%;
}

/* 卡片样式 */
.card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  padding: 16px;
  margin-bottom: 12px;
}

/* 输入框样式 */
.input {
  width: 100%;
  height: 32px;
  padding: 0 12px;
  border: 1px solid #D9D9D9;
  border-radius: 4px;
  font-size: 14px;
  color: #262626;
  background-color: #fff;
}
.input:focus {
  border-color: #007AFF;
  outline: none;
}

/* 列表样式 */
.list-item {
  display: flex;
  align-items: center;
  padding: 16px;
  background-color: #fff;
  border-bottom: 1px solid #F0F0F0;
}
.list-item:last-child {
  border-bottom: none;
}

/* 加载动画 */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

/* 空状态样式 */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  color: #595959;
}
.empty-text {
  font-size: 16px;
  margin-bottom: 24px;
}
</style>